#include "..\CommLib\CommStructs.h"
#include <maya/MNodeMessage.h>
#include <vector>

class VSyncViewer {

	static void OnChangeSelection(void* clientData);
	
	static MCallbackId g_ViewportRemoveObjectListenerCallback;
	static MCallbackId g_ViewportSelectionListenerCallback;
	static long g_SyncTimer;
	static const long g_SyncThrottle = 50;

	struct tSyncReport {

		bool IsGeometry;
		bool IsParameters;
		bool IsInstancing;
		bool IsDeformation;
	};

	static bool IsObjectSynchronized(MObject& targetObject, tSyncReport* pReport);
	
	static bool CheckMatch(MObject& targetObject, QuerysStructs::tGeometryHeader* pHeader);
	static bool CheckMatch(MObject& targetObject, QuerysStructs::tGeometryPartHeader* pHeader, uint partIndex);
	static bool CheckMatch(MObject& targetObject, QuerysStructs::tChannelHeader* pHeader, uint partIndex);
	static bool CheckMatch(MObject& targetObject, QuerysStructs::tInstancingHeader* pHeader);
	static bool CheckMatch(MObject& targetObject, QuerysStructs::tInstanceChildHeader* pHeader, uint childIndex);
	static bool CheckMatch(MObject& targetObject, QuerysStructs::tDeformationHeader* pHeader);

public:

	class Selection {
		friend class VSyncViewer;
		static bool InitCallbacks();
		static bool InitAttributes();
		static bool InitMaterials();

	public:
		static MObject			Transform;
		static MObject			Mesh;

		static bool IsValid();
		static void Release();
	};

	static void AddSamplerCallback(MObject material);
	static bool InitalizeSelectionListener();
	static void ReleaseSelectionListener();
	
	static bool CurrentSelection();
	static bool EntireScene();
	
	/*static bool ObjectDeformation(MObject& mesh = VSyncViewer::Selection::Mesh);
	static bool ObjectParameters(MObject& mesh = VSyncViewer::Selection::Mesh);
	static bool OnChangeSampler(MObject targetObject = VSyncViewer::Selection::Mesh, MString channelName = MString());
	static void OnChangeTransform(MObject targetObject = VSyncViewer::Selection::Mesh, MObject transformObject = VSyncViewer::Selection::Transform);
	static void OnChangeGeometry(MObject targetObject = VSyncViewer::Selection::Mesh);
	static bool ObjectInstancing(MObject targetObject = VSyncViewer::Selection::Mesh);*/


	class CallbackWrappers {
	public:

		/*static void SceneExited
		static void SceneSaved
		static void SceneOpened*/
		static void SceneRemoveObject(MObject& object, void* pClientData);
		static void RemoveObjectCallbacks(MObject& object);

		static void OnChangeSampler(MNodeMessage::AttributeMessage msg, MPlug& plug, MPlug& otherPlug, void* pClientData);
		static void OnChangeTransform( MNodeMessage::AttributeMessage msg, MPlug& plug, MPlug& otherPlug, void* pClientData);
		static void OnChangeGeometry( MNodeMessage::AttributeMessage msg, MPlug& plug, MPlug& otherPlug, void* pClientData);
	};
};